package cn.ming.wfchat.app.viewholder;

import android.content.Intent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.OnClick;
import cn.ming.wfchat.R;
import cn.ming.wfchat.app.dialog.RedPageDialog;
import cn.ming.wfchat.app.me.activity.RedPageListActivity;
import cn.ming.wfchat.kit.annotation.EnableContextMenu;
import cn.ming.wfchat.kit.annotation.MessageContentType;
import cn.ming.wfchat.kit.conversation.ConversationFragment;
import cn.ming.wfchat.kit.conversation.message.model.UiMessage;
import cn.ming.wfchat.kit.conversation.message.viewholder.NormalMessageContentViewHolder;
import cn.wildfirechat.message.SendRedPageMessageContent;

@MessageContentType({SendRedPageMessageContent.class})
@EnableContextMenu
public class SendRedPageMessageContentViewHolder extends NormalMessageContentViewHolder {

    @BindView(R.id.tv_money)
    TextView tv_money;
    @BindView(R.id.tv_title)
    TextView tv_title;
    @BindView(R.id.ll_layout)
    LinearLayout linearLayout;
    SendRedPageMessageContent content;
    private long messageId;

    public SendRedPageMessageContentViewHolder(ConversationFragment fragment, RecyclerView.Adapter adapter, View itemView) {
        super(fragment, adapter, itemView);
    }

    @Override
    public void onBind(UiMessage message) {
        content = (SendRedPageMessageContent) message.message.content;
        messageId = message.message.messageId;
        tv_money.setText(content.getSlogan());
        if (content.getIsstate() == 1) {
            linearLayout.setBackgroundResource(R.drawable.bg_5dp_ef_50);
        } else {
            linearLayout.setBackgroundResource(R.drawable.bg_5dp_ef);
        }
    }

    @OnClick(R.id.ll_layout)
    public void onClick(View view) {
        if (content.getIsstate() == 0) {
            RedPageDialog.newInstance(content, messageId).show(fragment);
        } else {
            Intent intent = new Intent(fragment.getActivity(), RedPageListActivity.class);
            intent.putExtra("hash", content.getHash());
            fragment.getActivity().startActivity(intent);
        }

    }


    @Override
    public boolean contextMenuItemFilter(UiMessage uiMessage, String tag) {
        return true;
    }
}
